package com.yunxin.download.server.infra.support.filed.transfer;

import com.yunxin.download.server.service.extenal.FileExportConfigDTO;
import com.yunxin.download.server.infra.support.filed.transfer.impl.*;

/**
 * @author zero°
 * @since 2023-06-15
 */
public enum FieldTransferContext {

    /**
     * 实例
     */
   X;

    /**
     * @param value value
     * @param fieldFormat fieldFormat
     *
     * @return Object
     */
    public Object transfer(Object value, FileExportConfigDTO.FieldFormat fieldFormat) {
        if (value == null) {
            return null;
        }
        final String type = fieldFormat.getType();
        FieldTransfer fieldTransfer = switch (type) {
            case "LocalDateTimeFormat" -> new LocalDateTimeTransfer();
            case "LocalDateFormat" -> new LocalDateTransfer();
            case "Integer" -> new IntegerTransfer();
            case "Decrypt" -> new DecryptTransfer();
            case "KvData" -> new KvDataTransfer();
            case "Desensitize" -> new DesensitizeTransfer();
            default -> new StringTransfer();
        };
        return fieldTransfer.transfer(value, fieldFormat);
    }
}
